package com.xiaotu.server.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xiaotu.common.util.StringUtil;
import com.xiaotu.spider.SupplementRunner;

import net.sf.json.JSONObject;

@RequestMapping(value="supplement",produces="text/html;charset=UTF-8")
@RestController
public class SupplementController {

	
	private static final Logger LOGGER = LoggerFactory
			.getLogger(SupplementController.class);
	
	/**
	 * 人工补爬接口 接口中 (接口中的1为爬取，0为跳过)
	 * @param jsonStr {"taskName":"DouBan","comment":"1","record":"0",
	 * "targetList":[{"tvid":"1105550","tvName":"一夜危机","tvType":"2"},
	 * {"tvid":"1121621","tvName":"Hello！女神","tvType":"5"}]}
	 */

	@RequestMapping(value="spiderRecord")
	public String spiderRecord(@RequestBody String spiderInfo,HttpServletRequest request){

		
		if(StringUtil.isEmpty(spiderInfo)){
			return "{'status':'1','message':'参数不可为空'}";
		}
		
//		String tvname = json.getString("tvName");
//		String tvId = json.getString("tvId");
//		JSONArray taskArray = json.getJSONArray("spiderInfo");
		try {
			JSONObject spiderInfoJSON = JSONObject.fromObject(spiderInfo);
			String seriesno = SupplementRunner.supplementSpiderRun(spiderInfoJSON);
			return "{'status':'0','message':'spiderStarted','seriesno':'"+seriesno+"'}";
		} catch (Exception e) {
			LOGGER.error("人工补爬异常("+spiderInfo+") ",e);
			return "{'status':'1','message':'"+e.getMessage()+"'}";
		}
		
	}
	
	
}
